import axios from "axios";
import _vue from "vue";
import qs from "qs";
console.log(process.env);
var http = axios.create({
  baseURL: process.env.VUE_APP_BASE_API
});

http.interceptors.request.use(config => {
  config.headers = {
    Authorization: _vue.$authorization(),
    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" //统一使用表单提交
  };
  config.transformRequest = data => {
    return qs.stringify(data);
  };

  config.withCredentials = true;
  return config;
});

http.interceptors.response.use(config => {
  if (config.status != 200) {
    _vue.$message({
      type: "warning",
      message: config.data.errorMessage
    });
  }
  return config;
});
/**
 *
 * @param {import("vue").VueConstructor} Vue
 */
export default function(Vue) {
  Vue.prototype.$http = http;
  Vue.$http = http;
}
